<?php
namespace App\Repositories\Admin;

use App\Models\Admin\NewsModel;
use App\Repositories\BaseRepository;

class NewsRepository extends BaseRepository
{
    protected $repository;

    public function __construct()
    {
        $this->repository = new NewsModel();
    }

    /**
     * 操作分页获取
     */
    public function getIndexList()
    {
        $models = $this->repository->orderBy('id','asc')
            ->paginate(10);
        $models->limit = 10;
        return $models;
    }

    public function getIndexByCid($cid,$page)
    {
        return $this->repository
            ->where('cid',$cid)
            ->orderBy('id','DESC')
            ->skip($page)
            ->take(10)
            ->get();
    }

    public function setAdd($data)
    {
        $data['created_at'] = time();
        return $this->repository->insertGetId($data);
    }

    public function setModify($data,$id)
    {
        $data['updated_at'] = time();
        return $this->repository->where('id',$id)
            ->update($data);
    }

    public function getShowOne($id)
    {
        return $this->repository->where('id',$id)->first();
    }
}